<template>
  <div class="tab-bar-item" @click="runPath">
    <div v-if="!isActive">
      <slot name="item-icon"></slot>
    </div>
    <div v-else>
      <slot name="item-icon-active"></slot>
    </div>
    <div :class="{isActive: isActive}">
      <slot name="item-text"></slot>
    </div>
  </div>
</template>

<script>
export default {
  name: "TabBarItem",
  data() {
    return {
      // isActive: true
    }
  },
  props: {
    path: String
  },
  computed: {
    isActive() {
      return this.$route.path.indexOf(this.path) !== -1
    }
  },
  methods: {
    runPath() {
      this.$router.replace(this.path)
    }
  },
}
</script>

<style scoped>
  .tab-bar-item {
    flex: 1;
    align-items: center;
    justify-content: center;
    text-align: center;
  }
  .tab-bar-item img {
    width: 24px;
    height: 24px;
    vertical-align: middle;
  }
  .tab-bar-item p {
    font-size: 12px;
  }
  .isActive {
    color: var(--color-high-text);
  }
</style>
